package com.pr.makfilm.user.pages.room.details.cmp;

import com.google.common.collect.Table;
import com.pr.makfilm.domain.Room;
import com.pr.makfilm.domain.RoomPlace;
import com.pr.makfilm.service.IRoomPlaceService;
import com.pr.makfilm.user.pages.room.create.preview.PreviewRowRepeater;
import com.pr.makfilm.user.utils.RoomPlaceUtils;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.panel.EmptyPanel;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.markup.repeater.RepeatingView;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.PropertyModel;
import org.apache.wicket.spring.injection.annot.SpringBean;

import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: Barbara
 * Date: 27.10.13
 * Time: 01:47
 * To change this template use File | Settings | File Templates.
 */
public class RoomDesignTab extends Panel
{
   @SpringBean
   private IRoomPlaceService roomPlaceService;

   private List<String> yLabels = new ArrayList<String>();

   private Table<Integer, Integer, RoomPlace> placeTable;

   private Room room;

   public RoomDesignTab(String id, IModel<Room> model)
   {
      super(id, model);
      room = (Room) getDefaultModelObject();
      List<RoomPlace> placeList = roomPlaceService.getByRoom(room);
      placeTable = RoomPlaceUtils.convertToTable(placeList);
   }

   @Override
   protected void onInitialize()
   {
      super.onInitialize();
      for (int i = 0; i < room.getRowCount(); i++)
      {
         RoomPlaceUtils.appendHeader(yLabels, i, room.getyStyle());
      }

      add(new PreviewRowRepeater("rows",
              new PropertyModel<Room>(this, "room"),
              new PropertyModel(this, "placeTable"),
              new PropertyModel(this, "yLabels")));

//      add(new RepeatingView("rows")
//      {
//         @Override
//         protected void onPopulate()
//         {
//            removeAll();
//            for (int i = 0; i < room.getColumnCount(); i++)
//            {
//               for (int j = 0; j< room.getRowCount(); j++)
//               {
//                  RoomPlace place = placeTable.get(j, i);
//                  if (place != null)
//                  {
//                     add(new Label(newChildId(), place.getLabel()));
//                  }
//                  else
//                  {
//                     add(new EmptyPanel(newChildId()));
//                  }
//               }
//            }
//         }
//      });
   }
}
